package com.groupbuying.storeinternal.controller.forInternal;

import com.groupbuying.storeinternal.service.StoreInternalAccountWxinfoRelService;
import com.groupbuying.storeinternal.utils.R;
import com.groupbuying.storeinternal.utils.apiresult.ApiResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.Set;

/**
 * 商户微信登录信息关联表
 *
 * @author gaoruijun
 * @email 18511893135@163.com
 * @date 2019-07-12 11:48:19
 */

@RestController
@RequestMapping("/storeAccountWxinfoRel")
public class StoreAccountInternalWxinfoRelController{
    public static final Logger logger = LoggerFactory.getLogger(StoreAccountInternalWxinfoRelController.class);
    @Autowired
    private StoreInternalAccountWxinfoRelService storeAccountWxinfoRelService;

    /**
     * 商户信息和openId绑定落库
     *
     * @param param
     * @return
     */
    @PostMapping("/loginStoreAccountWxInfo")
    public ApiResult saveStoreAccountWxInfo(@RequestParam Map<String, Object> param) {
        return storeAccountWxinfoRelService.getByAccountAndOpen(param);
    }



    /**
     * 退出登陆
     *
     * @param parma
     * @return
     */
    @PostMapping("/loginOut")
    public R loginOut(@RequestParam Map<String, String> parma) {
        logger.info("退出登陆的参数为parma:{}", parma);
        storeAccountWxinfoRelService.removeByAccountIdAndOpenId(parma);
        return R.ok();

    }

    @GetMapping("/getOpenIds")
    public Map<String, Set<String>> getOpenIds(String counterId) {

        return storeAccountWxinfoRelService.getOpenAndAccountByCounterId(counterId);
    }

    /**
     * 通过手机号删除微信用户登陆关联信息(目前没用，预备使用)
     * @param mobile
     * @return
     */
    @PostMapping("/loginOutByMobile")
    public R loginOutByMobile(@RequestParam("mobile") String mobile) {
        logger.info("手机号parma:{}", mobile);
        storeAccountWxinfoRelService.removeByMobile(mobile);
        return R.ok();

    }
    @PostMapping("/loginOutByOpenId")
    public ApiResult loginOutByOpenId(@RequestBody String code){
        logger.info("接收到的code为:{}",code);
        return storeAccountWxinfoRelService.deleteByOpenId(code);
    }
}
